;;; csde-csharpdoc-gen.el -- Csharpdoc builder
;; $Revision: 1.1 $ 

;; Adapted from the JDE by Matt Bruce <matt.bruce@morganstanley.com>
;; Maintainer:  Matt Bruce

;; JDE Author: Sergey A Klibanov <sakliban@cs.wustl.edu>
;; JDE Maintainer: Paul Kinnucan, Sergey A Klibanov

;; Keywords: csharp, tools

;; JDE Copyright (C) 2000, 2001 Paul Kinnucan.

;; Keywords: csharp, tools

;; Copyright (C) 2001 Matt Bruce

;; The JDE is Copyright (C) 1997, 1998, 1999, 2000, 2001 Paul Kinnucan.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.


;; The latest version of the CSDE is available at
;; <URL:http://www.sourceforge.com/>.

;; Please send any comments, bugs, or upgrade requests to
;; Matt Bruce (matt.bruce@morganstanley.com)

;;; Commentary:

;;; Code:

;;;;
;;;; Customization
;;;;

(defgroup csde-csharpdoc nil
  "Csharpdoc template generator"
  :group 'csde
  :prefix "csde-csharpdoc-")

(defcustom csde-csharpdoc-command-path "csharpdoc"
  "*Path to the csharpdoc executable."
  :group 'csde-csharpdoc
  :type 'string)

(defcustom csde-csharpdoc-display-doc t
  "*Display the documentation generated by the `csde-csharpdoc-make' command. ."
  :group 'csde-csharpdoc
  :type 'boolean)

(defcustom csde-csharpdoc-gen-detail-switch (list "-protected")
  "Specifies what access level switch to use.
  -public will show only public classes and members
  -protected will show protected and public classes and members
  -package will show package, protected, and public classes and members
  -private will show all classes and members"
  :group 'csde-csharpdoc
  :type '(list
	  (radio-button-choice
	   :format "%t \n%v"
	   :tag "Select the detail level switch you want:"
	   (const "-public")
	   (const "-protected")
	   (const "-package")
	   (const "-private"))))

(defcustom csde-csharpdoc-gen-packages nil
  "Specifies which packages or files csharpdoc should be run on."
  :group 'csde-csharpdoc
  :type '(repeat (string :tag "Path")))

(defcustom csde-csharpdoc-gen-destination-directory "CsharpDoc"
  "Specifies the directory where csharpdoc will put the generated files."
  :group 'csde-csharpdoc
  :type 'string)

(defcustom csde-csharpdoc-gen-link-URL nil
  "Specifies what URL's to link the generated files to.
   For more information, look at the -link option of the csharpdoc tool."
  :group 'csde-csharpdoc
  :type '(repeat (string :tag "URL")))

(defcustom csde-csharpdoc-gen-link-online nil
  "Specifies whether or not to use csde-csharpdoc-gen-link-URL."
  :group 'csde-csharpdoc
  :type 'boolean)

(defcustom csde-csharpdoc-gen-link-offline nil
  "Specifies URLs to link to and the local path to the directory holding the package-list for each URL.
   The second argument can be a URL (http: or file:). If it is a relative file name, it is relative to the directory
   from which csharpdoc is run."
  :group 'csde-csharpdoc
  :type '(repeat 
	  (cons :tag "Remote URL and directory holding package-list for that URL"
		(string :tag "URL")
		(string :tag "Path"))))

(defcustom csde-csharpdoc-gen-group nil
  "Specifies groups of packages with a group heading and package pattern.
   The heading is usually a string like Extension Packages. The pattern is
   any package name or wildcard matching that name. You can specify several
   packages by separating the package names by a semicolon."
  :group 'csde-csharpdoc
  :type '(repeat
	  (cons :tag "Package group name and contents"
		(string :tag "Heading")
		(string :tag "Package Pattern"))))

(defcustom csde-csharpdoc-gen-doc-title ""
  "Specifies the title to be placed near the top of the overview summary file."
  :group 'csde-csharpdoc
  :type 'string)

(defcustom csde-csharpdoc-gen-window-title ""
  "Specifies what should be placed in the HTML <title> tag.
   Quotations inside the title should be escaped."
  :group 'csde-csharpdoc
  :type 'string)

(defcustom csde-csharpdoc-gen-overview ""
  "Specifies where to get an alternate overview-summary.html.
   The path is relative to the sourcepath."
  :group 'csde-csharpdoc
  :type 'string)

(defcustom csde-csharpdoc-gen-doclet ""
  "Specifies the class file that starts an alternate doclet
   to generate the html files. This path is relative to docletpath"
  :group 'csde-csharpdoc
  :type 'string)

(defcustom csde-csharpdoc-gen-docletpath nil
  "Specifies the path in which the doclet should be searched for."
  :group 'csde-csharpdoc
  :type '(repeat (string :tag "Path")))

(defcustom csde-csharpdoc-gen-header ""
  "Specifies what html code should be placed at the top of each output file."
  :group 'csde-csharpdoc
  :type 'string)

(defcustom csde-csharpdoc-gen-footer ""
  "Specifies what html code should be placed at the bottom of each output file."
  :group 'csde-csharpdoc
  :type 'string)

(defcustom csde-csharpdoc-gen-bottom ""
  "Specifies what text or html code should be placed at the bottom
   below the navigation bar."
  :group 'csde-csharpdoc
  :type 'string)

(defcustom csde-csharpdoc-gen-helpfile ""
  "Specifies the help file to be used for the Help link in the Navigation bar."
  :group 'csde-csharpdoc
  :type 'string)

(defcustom csde-csharpdoc-gen-stylesheetfile ""
  "Specifies the path to an alternate HTML stylesheet file."
  :group 'csde-csharpdoc
  :type 'string)

(defcustom csde-csharpdoc-gen-split-index nil
  "Specifies whether or not the index should be split alphabetically
   one file per letter."
  :group 'csde-csharpdoc
  :type 'boolean)

(defcustom csde-csharpdoc-gen-use nil
  "Specifies whether or not to create \"Use\" pages"
  :group 'csde-csharpdoc
  :type 'boolean)

(defcustom csde-csharpdoc-gen-author t
  "Specifies whether or not to use @author tags"
  :group 'csde-csharpdoc
  :type 'boolean)

(defcustom csde-csharpdoc-gen-version t
  "Specifies whether or not to use @version tags"
  :group 'csde-csharpdoc
  :type 'boolean)

(defcustom csde-csharpdoc-gen-serialwarn nil
  "Specifies whether or not to generate compile-time errors for missed @serial tags"
  :group 'csde-csharpdoc
  :type 'boolean)

(defcustom csde-csharpdoc-gen-nodeprecated nil
  "Specifies whether or not to remove all references to deprecated code"
  :group 'csde-csharpdoc
  :type 'boolean)

(defcustom csde-csharpdoc-gen-nodeprecatedlist nil
  "Specifies whether or not to remove references to deprecated code
   from the navigation bar, but not the rest of the documents."
  :group 'csde-csharpdoc
  :type 'boolean)

(defcustom csde-csharpdoc-gen-notree nil
  "Specifies whether or not to omit generating the class/interface hierarchy."
  :group 'csde-csharpdoc
  :type 'boolean)

(defcustom csde-csharpdoc-gen-noindex nil
  "Specifies whether or not to omit generating the index."
  :group 'csde-csharpdoc
  :type 'boolean)

(defcustom csde-csharpdoc-gen-nohelp nil
  "Specifies whether or not to omit the HELP link in the navigation bar of each page."
  :group 'csde-csharpdoc
  :type 'boolean)

(defcustom csde-csharpdoc-gen-nonavbar nil
  "Specifies whether or not to omit generating the navigation bar at the top of each page."
  :group 'csde-csharpdoc
  :type 'boolean)

(defcustom csde-csharpdoc-gen-verbose nil
  "Specifies whether or not csharpdoc should be verbose about what it is doing."
  :group 'csde-csharpdoc
  :type 'boolean)


(defcustom csde-csharpdoc-gen-args nil
  "Specifies any other arguments that you want to pass to csharpdoc."
  :group 'csde-csharpdoc
  :type '(repeat (string :tag "Argument")))


;;;###autoload
(defun csde-csharpdoc-make ()
  "Generates csharpdoc for the current project. This command runs the
CSDE csharpdoc program to generate the documentation. The variable
`csde-csharpdoc-command-path' specifies the path of the csharpdoc excutable.
The variable `csde-global-classpath' specifies the csharpdoc 
-classpath argument. The variable `csde-db-source-directories'
specifies the csharpdoc  -sourcepath argument. You can specify all
other csharpdoc options via CSDE customization variables. To specify the
options, select Project->Options->Csharpdoc from the CSDE menu. Use 
`csde-csharpdoc-gen-packages' to specify the packages, classes, or source
files for which you want to generate csharpdoc. If this variable is nil,
this command generates csharpdoc for the Csharp source file in the current
buffer. If `csde-csharpdoc-display-doc' is nonnil, this command displays
the generated documentation in a browser."
  (interactive)
  (save-some-buffers)

  
  (if (not (directory-files csde-csharpdoc-gen-destination-directory nil nil nil)) 
      (make-directory csde-csharpdoc-gen-destination-directory))

  (let ((arguments 
	 (format "%s -d %s %s"
		 csde-csharpdoc-command-path
		 csde-csharpdoc-gen-destination-directory
		 (car csde-csharpdoc-gen-detail-switch))))

    ;;Insert online links
    (if csde-csharpdoc-gen-link-online 
	(setq arguments 
	      (concat 
	       arguments
	       (mapconcat
		(lambda (link) (format " -link \"%s\"" link))
		csde-csharpdoc-gen-link-URL " "))))
    
    ;;Insert offline links
    (if csde-csharpdoc-gen-link-offline
	(setq arguments
	      (concat 
	       arguments
	       (mapconcat
		(lambda (link) 
		  (format " -linkoffline \"%s\" \"%s\" " 
			  (car  link) (cdr link)))
		csde-csharpdoc-gen-link-offline " "))))

    ;;Insert -group
    (if csde-csharpdoc-gen-group
	(setq arguments
	      (concat
	       arguments
	       (mapconcat
		(lambda (group) 
		  (format " -group \"%s\" \"%s\" " 
			  ( car group) (cdr group)))
		csde-csharpdoc-gen-group " "))))

    ;; Insert classpath
    (if csde-global-classpath
	(setq arguments
	      (concat
	       arguments " "
	       (csde-build-classpath-arg
		csde-global-classpath csde-quote-classpath))))

    ;; Insert sourcepath
    (if csde-db-source-directories
	(setq arguments
	      (concat
	       arguments 
	       (format " -sourcepath \"%s\""
		       (mapconcat
			(lambda (path) path)
			csde-db-source-directories 
			path-separator)))))


    ;; Insert bootclasspath
    (if csde-compile-option-bootclasspath
	(setq arguments
	      (concat
	       arguments " "
	       (csde-build-path-arg
		"-bootclasspath "
		csde-compile-option-bootclasspath
		csde-quote-classpath))))

    ;; Insert extdirs
    (if csde-compile-option-extdirs
	(setq arguments
	      (concat
	       arguments " "
	       (csde-build-path-art
		"-extdirs "
		csde-compile-option-extdirs
		csde-quote-classpath))))

    ;; Insert windowtitle
    (if (not (equal "" csde-csharpdoc-gen-window-title))
	(setq arguments
	      (concat
	       arguments " -windowtitle \""
	       csde-csharpdoc-gen-window-title "\" ")))

    ;; Insert doctitle
    (if (not (equal "" csde-csharpdoc-gen-doc-title))
	(setq arguments
	      (concat
	       arguments " -doctitle \""
	       csde-csharpdoc-gen-doc-title "\" ")))

    ;; Insert header
    (if (not (equal "" csde-csharpdoc-gen-header))
	(setq arguments
	      (concat
	       arguments " -header \""
	       csde-csharpdoc-gen-header "\" ")))

    ;; Insert footer
    (if (not (equal "" csde-csharpdoc-gen-footer))
	(setq arguments
	      (concat
	       arguments " -footer \""
	       csde-csharpdoc-gen-footer "\" ")))

    ;; Insert bottom
    (if (not (equal "" csde-csharpdoc-gen-bottom))
	(setq arguments
	      (concat
	       arguments " -bottom \""
	       csde-csharpdoc-gen-bottom "\" ")))

    ;; Insert helpfile
    (if (not (equal "" csde-csharpdoc-gen-helpfile))
	(setq arguments
	      (concat
	       arguments " -helpfile \""
	       csde-csharpdoc-gen-helpfile "\" ")))

    ;; Insert stylesheet
    (if (not (equal "" csde-csharpdoc-gen-stylesheetfile))
	(setq arguments
	      (concat
	       arguments " -stylesheetfile \""
	       csde-csharpdoc-gen-stylesheetfile "\" ")))

    ;; Insert -overview
    (if (not (equal "" csde-csharpdoc-gen-overview))
	(setq arguments
	      (concat
	       arguments " -overview \""
	       csde-csharpdoc-gen-overview "\" ")))

    ;; Insert -doclet
    (if (not (equal "" csde-csharpdoc-gen-doclet))
	(setq arguments
	      (concat
	       arguments " -doclet \""
	       csde-csharpdoc-gen-doclet "\" ")))

    ;; Insert -docletpath
    (if csde-csharpdoc-gen-docletpath
	(setq arguments
	      (concat 
	       arguments " "
	       (csde-build-path-arg 
		"-docletpath "
		csde-csharpdoc-gen-docletpath
		csde-quote-classpath))))

    ;; Inser -use
    (if csde-csharpdoc-gen-use
	(setq arguments
	      (concat
	       arguments " -use ")))

    ;;Insert -author
    (if csde-csharpdoc-gen-author
	(setq arguments
	      (concat
	       arguments " -author ")))
    
    ;;Insert -version
    (if csde-csharpdoc-gen-version
	(setq arguments
	      (concat
	       arguments " -version ")))

    ;;Insert -splitindex
    (if csde-csharpdoc-gen-split-index
	(setq arguments
	      (concat
	       arguments " -splitindex ")))

    ;;Insert -nodeprecated
    (if csde-csharpdoc-gen-nodeprecated
	(setq arguments
	      (concat 
	       arguments " -nodeprecated ")))

    ;;Insert -nodeprecatedlist
    (if csde-csharpdoc-gen-nodeprecatedlist
	(setq arguments
	      (concat 
	       arguments " -nodeprecatedlist ")))

    ;;Insert -notree
    (if csde-csharpdoc-gen-notree
	(setq arguments
	      (concat
	       arguments " -notree ")))

    ;;Insert -noindex
    (if csde-csharpdoc-gen-noindex
	(setq arguments
	      (concat
	       arguments " -noindex ")))

    ;;Insert -nohelp
    (if csde-csharpdoc-gen-nohelp
	(setq arguments
	      (concat
	       arguments " -nohelp ")))

    ;;Insert -nonavbar
    (if csde-csharpdoc-gen-nonavbar
	(setq arguments
	      (concat
	       arguments " -nonavbar ")))

    ;;Insert -serialwarn
    (if csde-csharpdoc-gen-serialwarn
	(setq arguments
	      (concat
	       arguments " -serialwarn ")))

    ;;Insert -verbose
    (if csde-csharpdoc-gen-verbose
	(setq arguments
	      (concat
	       arguments " -verbose ")))

    ;;Insert other tags
    (if csde-csharpdoc-gen-args
	(setq arguments
	      (concat
	       arguments " " 
	       (mapconcat
		(lambda (arg) arg)
		csde-csharpdoc-gen-args " "))))

    ;;Insert packages/files
    (if csde-csharpdoc-gen-packages
	(setq arguments 
	      (concat 
	       arguments
	       (mapconcat
		(lambda (packagename) (format "%s" packagename))
		csde-csharpdoc-gen-packages " ")))
      (setq arguments
	    (concat arguments " " (buffer-file-name))))
    
    (setq compilation-finish-function
	  (lambda (buf msg)
	    (message msg)
	    (if (and
		 csde-csharpdoc-display-doc
		 (string-match "finished" msg))
		(browse-url-of-file 
		 (concat csde-csharpdoc-gen-destination-directory "/index.html")))))

    (compile-internal arguments "No errors now!")))

(provide 'csde-csharpdoc-gen)

;;
;; $Log: csde-csharpdoc-gen.el,v $
;; Revision 1.1  2001/02/12 05:50:15  paulk
;; Initial XEmacs revision.
;;
;; Revision 1.2  2001/01/27 05:53:38  paulk
;; No longer inserts -sourcepath argument twice in the csharpdoc command line.
;;
;; Revision 1.1  2000/10/20 04:06:34  paulk
;; Initial version.
;;
;;

;;; csde-csharpdoc-gen.el ends here
